[Xamarin.Android.Net] Changes to CancellationToken support in AndroidClientHandler#321
[Xamarin.Android.Net] Changes to CancellationToken support in AndroidClientHandler#321leonluc-dev wants to merge 2 commits intodotnet:masterfrom leonluc-dev:master
Conversation
…ecks added Extra cancellationToken checks added to the DoProcessRequest method. This is to fix an issue where the cancellation would be delayed whenever the httpConnection.ConnectAsync() or httpConnection.CopyToAsync() methods run for a long time (in case of a slow connection or timeout). See Comment 6 and 7 of https://bugzilla.xamarin.com/show_bug.cgi?id=44673
Using the ReadAsStreamAsync method exposes the content as a stream. The CopyToAsync method in .NET streams support CancellationTokens.
|
Hello! I'm the build bot for the Mono project. I need approval from a Mono team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done. Contributors can ignore this message. |
|
Hi @gameleon-dev, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
|
|
||
| if (cancellationToken.IsCancellationRequested) | ||
| { | ||
| httpConnection.Disconnect(); |
There was a problem hiding this comment.
Indentation here is weird. Is there an extra tab on this line and the following?
|
build |
2 similar comments
|
build |
|
build |
|
This was applied as commit 0c35978. Thank you for the PR! |
|
I am trying to download thousand files. Whenever httpConnection.ConnectAsync() called new task, which waits for cancellation token to be cancelled, passed to Task.WhenAny construction. But if the cancellation token never triggered, task never finishes, hanging on cancellationToken.WaitHandle.WaitOne(), causing mono to create many threads, that never finish.
|
|
@lexboss93 That is indeed an issue. It could be solved by creating a linked token to cancel the WaitOne like this: |
|
I have created a followup pull request at #344 |
|
Has this fix made it into a release yet? |
These changes are meant to improve cancellation token support for the AndroidClientHandler.
Previously the ConnectAsync and CopyToAsync calls would delay cancellation until those methods finished running, which could take up to 30 seconds on slow connections or in case of a timeout.
ConnectAsync: Since ConnectAsync doesn't support cancellation through tokens it had to be wrapped in a WhenAny construction with a task that would be linked to the cancellation token.
CopyToAsync: By exposing the HttpContent as a stream using ReadAsStreamAsync method, the CopyToAsync overload which supports cancellation tokens can be used.